package qj.util.tree;

public class Trees {

    public static TreeNode<String> toTree(String group, String... dividers) {
        for (String divider : dividers) {
            TreeNode<String> tree = divideBy(group, divider);
            if (tree != null) {
                return tree;
            }
        }

        return new TreeNode<String>(group);
    }

    public static TreeNode<String> divideBy(String group, String operator) {
        int orPos = group.indexOf(operator);
        if (orPos > -1) {
            return new TreeNode<String>(operator, group.substring(0, orPos), group.substring(orPos + operator.length()));
        }
        return null;
    }
}
